package com.yzt.user.service.impl;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yzt.base.kit.Base;
import com.yzt.base.service.impl.BaseServiceImpl;
import com.yzt.base.utils.StringUtils;
import com.yzt.user.entity.Info;
import com.yzt.user.mapper.InfoMapper;
import com.yzt.user.service.IInfoService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Y
 * @since 2020-12-08
 */
@Service
@CacheConfig(cacheNames = "user", keyGenerator = "keyGenerator")
public class InfoServiceImpl extends BaseServiceImpl<InfoMapper, Info> implements IInfoService {

	@Override
	@Cacheable
	public Base<PageInfo<Info>> userList(int page, int limit) {
		PageInfo<Info> list = PageHelper.startPage(page, limit).doSelectPageInfo(() -> this.list());
		return Base.okData(list);
	}

	@Override
	public Base<Object> addInfo(Info info) {
		Info i = new Info();
		i.setUserName(Math.random() + "");
		i.setUserPass(StringUtils.encoder("0"));
		this.save(i);
		boolean b = this.save(info);
		if (b) {
			return Base.ok();
		}
		return Base.fail();
	}

}
